package edu.hit.irlab.coref.trainer;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import nlpeap.ml.FeatureDescription;
import nlpeap.ml.InstanceWriter;

import edu.hit.irlab.coref.PairFeatureExtractor;
import edu.hit.irlab.coref.PairInstance;
import edu.hit.irlab.coref.mentionfinder.Mention;
/**
 * The abstract class of trainer for Corefrence Resolution, the
 * trainer construct instances from given mentions, and write
 * them into file(training_data) uses particular <i>InstanceWriter</i>
 * 
 * @author chuter
 *
 */
public abstract class CorfTrainer {
    protected final List<PairFeatureExtractor> _fes;
    protected final InstanceWriter _iw;
    
    public CorfTrainer(List<PairFeatureExtractor> fes, InstanceWriter iw)
    	throws IOException
    {
    	_fes = fes;
    	_iw = iw;
    	ArrayList<FeatureDescription> fds = new ArrayList<FeatureDescription>();
        for (PairFeatureExtractor fe : _fes) {
            fe.describeFeatures(fds);
        }
        
        fds.add(PairInstance.FD_POSITIVE);
        iw.setHeader(fds, "corf");
    }
    
    /**
     * Write all the instances construct from the mentions, 
     * @param mention_arr
     * @throws IOException 
     */
    public abstract void train(Mention[] mention_arr) throws IOException;
}
